package nezumi.sensing;

import nezumi.util.Probability;

/**
 * Models the IR sensor as a normal distribution on the inverse of the distance
 * to the closest obstacle.
 * 
 * @author rui
 * 
 */
public abstract class AGaussianSensorModel implements ISensorModel {

	private final double sigma;

	public AGaussianSensorModel(final double stddev) {
		this.sigma = stddev;
	}

	/**
	 * Computes the probability as the area of the normal's probability density
	 * function matching the area occupied by a cell at distance dist. We
	 * actually use the inverse of the distance for our computations, thus
	 * enabling us to use a gaussian distribution with a constant standard
	 * deviation. arg dist - distance in meters.
	 */
	public double computeProb(final double mu, double x) {

		double a = computeA(x), b = computeB(x);

		//System.out.printf("computing cdf between %.2f and %.2f, x=%.2f\n", a, b, Math.toDegrees(x));

		return Probability.normalCDF((b - mu) / sigma)
				- Probability.normalCDF((a - mu) / sigma);
	}

	protected abstract double computeA(final double x);

	protected abstract double computeB(final double x);

}
